package com.jp.spider.util;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by liujianpeng on 2017/9/5 0005.
 */
public class ImageByte {

    public byte[] convertImageByByte(String Imgurl){
        URL url = null;
        byte[] decode = null;
        try {
            url = new URL(Imgurl);
            URLConnection conn = url.openConnection();
            InputStream in2 = conn.getInputStream();
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int len = 0;
            while (-1 != (len = in2.read(buffer))) {
                outStream.write(buffer, 0, len);
            }
            decode = outStream.toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return decode;
    }
}

